
module.exports = app => {

    return class PracticeController extends app.Controller {
        async index() {

            let params = this.ctx.request.query;

            let type = params.type;
            let pointId = params.pointId;
            let courseId = params.courseId;
            //创建练习
            // let exerciseId = await this.service.exercise.add({
            //     type,
            //     courseId
            // });

            let questions = await this.service.subject.list({
                type,
                pointId,
                courseId
            });

            await this.ctx.render('study/practice/index.js', {
                questions,
                type,
                courseId
            });
        }

        async detail() {
            let params = this.ctx.request.query;
            let questions = await this.service.exercise.detail(params);
            await this.ctx.render('study/practice/detail/index.js', {
                questions,
                params
            });
        }
        async result() {
            let id = this.ctx.request.query.id;
            let report = await this.service.exercise.report({
                id
            });
            await this.ctx.render('study/practice/result/index.js', {
                report
            });
        }

        async history() {
            let method = this.ctx.request.method;
            if ("GET" == method){
                await this.ctx.render('study/practice/history/index.js');
            }else{
                let type = this.ctx.request.body.type;
                let pageNo = this.ctx.request.body.pageNo;
                let data = await this.service.exercise.historyExercise({ type, pageNo });
                this.success(data);
            }
        }

        /**
         * 练习提交
         * @returns {Promise<void>}
         */
        async submit() {
            let params = this.ctx.request.body;
            let data = await this.service.subject.submit(params);
            console.log(data);
            this.success(data);
        }


    };
};
